package com.okami.designpatterns.factory.simplefactory;

import com.okami.designpatterns.factory.CircularShape;
import com.okami.designpatterns.factory.NoProductException;
import com.okami.designpatterns.factory.Shape;
import com.okami.designpatterns.factory.SquareShape;

/**
 * @description: 简单工厂，生产一种产品。可以设置成单例模式
 * @author: TanJingyu
 * @create: 2020-12-09 10:33
 **/
class Factory {
    static Shape getInstance(String shapStr) throws NoProductException {
        if ("circular".equalsIgnoreCase(shapStr)) {
            return new CircularShape("这是圆形，哈哈！");
        }else if ("square".equalsIgnoreCase(shapStr)) {
            return new SquareShape("这是正方形，哈哈！");
        }else {
            throw new NoProductException("抱歉，生产不了" + shapStr);
        }
    }
}
